﻿using System;
using System.Windows.Forms;

namespace 网络
{
    public partial class FormSaveWeb : Form
    {
        Mht.Builder _mht;

        public FormSaveWeb()
        {
            InitializeComponent();

            _mht = new Mht.Builder();
            _mht.Play += new Mht.Builder.PlayEventHandler(EventHandlerPlay);
        }

        /// <summary>
        /// 打开
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Uri uri = new Uri(this.toolStripTextBox1.Text.Trim());
            this.webBrowser1.Url = uri;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            try
            {
                //*********************************************************
                //网上的一个方法 报com组建错误
                //*********************************************************
                //if (toolStripTextBox1.Text != "")
                //{
                //    CDO.Message msg = new CDO.MessageClass();
                //    CDO.Configuration c = new CDO.ConfigurationClass();
                //    msg.Configuration = c;
                //    msg.CreateMHTMLBody(toolStripTextBox1.Text, CDO.CdoMHTMLFlags.cdoSuppressAll, "", "");
                //    msg.GetStream().SaveToFile(@"d:\1.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                //}

                //*********************************************************
                //
                //*********************************************************

                //Cursor.Current = Cursors.WaitCursor
                //Dim st As Mht.Builder.FileStorage
                //If MemoryRadioButton.Checked Then
                //    st = Mht.Builder.FileStorage.Memory
                //End If
                //If DiskTempRadioButton.Checked Then
                //    st = Mht.Builder.FileStorage.DiskTemporary
                //End If
                //If DiskPermRadioButton.Checked Then
                //    st = Mht.Builder.FileStorage.DiskPermanent
                //End If

                //'*********************************************************
                //'_mht主要的生成类
                //'*********************************************************
                //MhtFileTextBox.Text = _mht.SavePageArchive(MhtFileTextBox.Text, st, UrlTextBox.Text)
                //Cursor.Current = Cursors.Default
                //ViewMhtButton.Enabled = True

                Mht.Builder.FileStorage st = Mht.Builder.FileStorage.Memory;
                string strDes = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                strDes = strDes.Replace(@"\\", @"\");
                if (!strDes.EndsWith(@"\"))
                {
                    strDes = strDes + @"\";
                }

                _mht.SavePageArchive(strDes, st, toolStripTextBox1.Text);

                //System.Windows.Forms.SendKeys.Send("{HOME}");
            }
            catch (Exception ee)
            {
            }
        }

        //    Sub EventHandlerPlay(ByVal sender As Object, ByVal e As Int32)
        //    ' Handle the event.
        //    'MsgBox("EventHandler caught event.")
        //    Me.ProgressBar1.Value = e
        //    If e = 100 Then
        //        MsgBox("完成。。。。")
        //    End If

        //End Sub

        private void EventHandlerPlay(Object sender, int i)
        {
            this.toolStripProgressBar1.Value = i;
            if (i == 100)
            {
                MessageBox.Show("完成。。。。");
            }
        }

        private void FormSaveWeb_Load(object sender, EventArgs e)
        {
        }
    }
}